//
// Created by aaa on 2025/7/12.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 1e4 + 10;

int n,m,w,v,s;
int a[N],b[N],c[N],dp[N];


//混合背包
//4 5
//1 2 -1
//2 4 1
//3 4 0
//4 5 2
int main(){
    cin >> n >> m;
    int num = 1;
    for(int i = 1;i <= n;i++){
        cin >> w >> v >> s;

        if(s == 0){
            a[num] = w;
            b[num] = v;
            c[num++] = 0;
        }else{
            if(s == -1) s = 1;
            int k = 1;
            while(s >= k){
                a[num] = k * w;
                b[num] = k * v;
                c[num++] = 1;
                s -= k;
                k <<= 1;
            }

            if(s){
                a[num] = s * w;
                b[num] = s * v;
                c[num++] = 1;
            }
        }
    }

    for(int i = 1;i < num;i++){
        if(c[i] == 1){
            for(int j = m;j >= a[i];j--) dp[j] = max(dp[j],dp[j - a[i]] + b[i]);
        }else{
            for(int j = a[i];j <= m;j++) dp[j] = max(dp[j],dp[j - a[i]] + b[i]);
        }
    }

    cout << dp[m];

    return 0;
}